//author: create by SunJH
//时间: 2021/12/14 0014
//邮箱: 965989158@qq.com
//描述: 极光推送的测试页面

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/counter/counter_jg_test.dart';
import 'package:flutter_app/stateLearn/click_txt.dart';
import 'package:flutter_app/utils/jg_util.dart';
import 'package:flutter_app/utils/log_util.dart';
import 'package:get/get.dart';

class JgPushTest extends GetView<JgTestController> {
  const JgPushTest({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Get.put(JgTestController());
    return Scaffold(
      body: Container(
        alignment: Alignment.center,
        child: ListView(
          children: [
            ClickTxt(
                info: "抛出异常",
                onPressed: () {
                  1 / 0;
                }),
            ClickTxt(
                info: "检测通知权限",
                onPressed: () {
                  JGUtil.instance.checkNotificationPermission();
                }),
            ClickTxt(
                info: "发送本地服务",
                onPressed: () {
                  controller.sendLocalNotification();
                }),
            ClickTxt(
                info: "显示一个底部弹窗",
                onPressed: () {
                  Get.snackbar("底部弹窗测试", "多冷啊，我在东北玩泥巴",
                      snackPosition: SnackPosition.BOTTOM);
                }),
            Obx(() => ClickTxt(
                info: "开启/关闭推送,当前状态:${controller.isOpenJG.value ? "开启" : "关闭"}",
                onPressed: () {
                  if (controller.isOpenJG.value) {
                    controller.jPush.stopPush();
                    controller.isOpenJG.value = false;
                  } else {
                    controller.jPush.resumePush();
                    controller.isOpenJG.value = true;
                  }
                })),
            TextField(
              onChanged: (info) {
                controller.jGAlias.value = info;
              },
              decoration: const InputDecoration(labelText: "请输入别名"),
            ),
            Obx(() => ClickTxt(
                info: "设置别名(当前别名:${controller.jGAlias.value})",
                onPressed: () {
                  controller.setJGAlias();
                })),
            ClickTxt(
                info: "清除别名",
                onPressed: () {
                  controller.deleteAlias();
                }),
            ClickTxt(
                info: "获取注册id",
                onPressed: () {
                  controller.jPush
                      .getRegistrationID()
                      .then((value) => LogUtil.logE(value));
                }),
            TextField(
              onChanged: (info) {
                controller.jGAlias.value = info;
              },
              decoration: const InputDecoration(labelText: "请输入tag"),
            ),
            Obx(() => Text("当前Tag列表${controller.tags}")),
            ClickTxt(
                info: "清除所有Tag",
                onPressed: () {
                  controller.clearTag();
                }),
            ClickTxt(info: "删除当前输入Tag", onPressed: () {}),
            ClickTxt(
                info: "产生错误",
                onPressed: () {
                  int.parse("source");
                })
          ],
        ),
      ),
    );
  }
}
